package ca.camosun.bouncer;

import ca.camosun.bouncer.components.SensorWrapper;
import ca.camosun.bouncer.components.Tickable;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.hardware.SensorManager;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.widget.TextView;

public class SensorInputActivity extends Activity implements Tickable {

	private TextView text;
	private SensorWrapper sensor;
	private DisplayMetrics displayMetrics;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sensor);

		text = (TextView) findViewById(R.id.TextView1);
		text.setText("No information yet.");

		sensor = new SensorWrapper(
				(SensorManager) getSystemService(Context.SENSOR_SERVICE), this);

		displayMetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	protected void onResume() {
		super.onResume();
		sensor.startListening();
	}

	@Override
	public void tick(int x, int y, int z) {
		int rotation = getWindowManager().getDefaultDisplay().getRotation();

		text.setText("");
		text.setLines(10);

		text.append("Accelerometer:\n");
		text.append("	x: " + x + "\n");
		text.append("	y: " + y + "\n");
		text.append("	z: " + z + "\n");

		text.append("\n");

		text.append("Display Metrics:\n");
		text.append("	widthPixels: " + displayMetrics.widthPixels + "\n");
		text.append("	heightPixels: " + displayMetrics.heightPixels + "\n");
		text.append("	rotation: " + rotation);
	}

}